package com.launcher.wkang;

import android.annotation.SuppressLint;
import android.app.AlarmManager;
import android.app.Application;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.os.RemoteException;
import android.util.Log;

import com.eink.swtcon.ISwtconControl;
import com.eink.swtcon.SwtconControl;
import com.launcher.wkang.Exception.CrashHandler;
import com.launcher.wkang.activity.StudentSettingActivity;
import com.launcher.wkang.receive.ActionBroadCast;
import com.launcher.wkang.util.PhoneUtil;

import java.util.HashMap;
import java.util.Map;

import cn.jpush.android.api.JPushInterface;

//import io.rong.imlib.RongIMClient;
//import io.rong.push.RongPushClient;

public class App extends Application {
    public double latitude;
    public double longitude;
    public String deviceId;
    private ISwtconControl mSwtcon;
    private int setNum=0;
    private int maxSetNum=20;
    private static App instance;
    public boolean isProhibit;
//    是否允许接电话
    public boolean isAnswer;
    public boolean isRegister;
    public static Map<String,Integer> iconMap;
    public static  App getINstance(){
        return instance;
    }




    @SuppressLint("WrongConstant")
    @Override

    public void onCreate() {
        super.onCreate();
        CrashHandler.getInstance().init(this);
        instance=this;
        isProhibit=false;
        isAnswer=true;
        isRegister=false;
        initIconMap();
//        PhoneUtil.startUp(11,58,getApplicationContext());
//        PhoneUtil.shutDown(16, 14, getApplicationContext());
//        ######################################
        /**
         * 初始化融云
         */
//        RongIMClient.init(this);
//        RongPushClient.init(this,"e0x9wycfe4x6q");
//        shutDown();
        //
        JPushInterface.setDebugMode(true);
        JPushInterface.init(this);

        mSwtcon=SwtconControl.getService();
        setNum=0;
        maxSetNum=10;

//       setsetWaveformMode(2,1);
//                    setsetWaveformMode();
        try {
            if(mSwtcon!=null) {
                mSwtcon.setWaveformMode(2, 1);
            }
            new android.os.Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    try {
                        if(mSwtcon!=null) {
                            mSwtcon.setWaveformMode(5, 1);
                        }
                    } catch (RemoteException e) {
                        e.printStackTrace();
                    }
                }
            },100);
        } catch (RemoteException e) {
            e.printStackTrace();
        }
//        PhoneUtil.shutDown(0,0,getApplicationContext());
//        PhoneUtil.startUp(0,0,getApplicationContext());



    }


    public void setsetWaveformMode(final int lev,final int base){
        try {
            Log.d("WeikangLauncher","WeikangLauncher application setNum="+setNum+"maxSetNum="+maxSetNum);
            if (setNum>maxSetNum&&mSwtcon!=null){
                mSwtcon.setWaveformMode(2, 1);
                mSwtcon.setHandwrite(1);
                mSwtcon.setHandwriteColor(0);
                setNum=0;
                new android.os.Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            mSwtcon.setWaveformMode(lev, base);
                            mSwtcon.setHandwrite(1);
                            mSwtcon.setHandwriteColor(0);
                        } catch (RemoteException e) {
                            e.printStackTrace();
                        }
//                        App.getINstance().setsetWaveformMode(1,1);
                    }
                },100);
            }else {
                mSwtcon.setWaveformMode(lev, base);
                mSwtcon.setHandwrite(1);
                mSwtcon.setHandwriteColor(0);
            }
//

            return;
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }
    private void initIconMap(){
        iconMap=new HashMap<String, Integer>();
        iconMap.put("com.android.music",R.mipmap.music);
        iconMap.put("com.google.android.videos",R.mipmap.video);
        iconMap.put("com.mediatek.filemanager",R.mipmap.file_management);
        iconMap.put("com.android.deskclock",R.mipmap.clock);
        iconMap.put("com.android.calendar",R.mipmap.calendar);
        iconMap.put("com.android.gallery3d",R.mipmap.album);
    }
//    private void shutDown(){
//        AlarmManager am = (AlarmManager)
//                getSystemService(Context.ALARM_SERVICE);
//
////        Intent intent = new Intent(
////                "com.android.settings.action.REQUEST_POWER_OFF");
//
//        Intent intent = new Intent(
//                "android.intent.action.ACTION_SHUTDOWN");
//
//
//
//        PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0,
//                intent, PendingIntent.FLAG_CANCEL_CURRENT);
//        am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
//        am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), pendingIntent);
//    }
}
